package com.ctshk.rpc.order.tour.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.common.vo.OrderRefundDTO;
import com.ctshk.rpc.order.tour.base.CustomBaseMapper;
import com.ctshk.rpc.order.tour.dto.SeriesOrderTouristRefundDetailListDTO;
import com.ctshk.rpc.order.tour.dto.SeriesOrderTouristRefundDetailListTripDTO;
import com.ctshk.rpc.order.tour.entity.SeriesOrderTouristRefundDetail;
import com.ctshk.rpc.order.tour.req.SeriesOrderTouristRefundDetailListReq;
import com.ctshk.rpc.order.tour.req.SeriesOrderTouristRefundDetailListTripReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

/**
 * <p>
 * 系列团退款明细 Mapper 接口
 * </p>
 *
 * @author 谭响
 * @since 2021-01-28
 */
public interface SeriesOrderTouristRefundDetailMapper extends CustomBaseMapper<SeriesOrderTouristRefundDetail> {

    @SelectProvider(type = SeriesOrderTouristRefundDetailProvider.class, method = "selectListBySelective")
    IPage<SeriesOrderTouristRefundDetailListDTO> selectListBySelective(IPage<SeriesOrderTouristRefundDetailListReq> pageParam,
                                                                       @Param("req") SeriesOrderTouristRefundDetailListReq req);

    @SelectProvider(type = SeriesOrderTouristRefundDetailProvider.class, method = "selectListTripBySelective")
    IPage<SeriesOrderTouristRefundDetailListTripDTO> selectListTripBySelective(IPage<SeriesOrderTouristRefundDetailListTripReq> pageParam,
                                                                               @Param("req")SeriesOrderTouristRefundDetailListTripReq req);

    /**
     * 批量删除退款明细
     * @param id
     * @param userId
     */
    @Select("UPDATE t_series_order_tourist_refund_detail\n" +
            "SET is_deleted = 1,modified_id = #{user_id}\n" +
            "WHERE refund_id = #{refund_id} AND is_deleted = 0")
    void batchDelByRefundId(@Param("refund_id") Long id, @Param("user_id") Long userId);

    /**
     * 退款信息列表
     * @param refundId
     * @return
     */
    @Select("SELECT a.id,a.refund_number,a.refund_account,a.total_receivables,a.paid_in_amount,c.cn_fullname AS touristName,\n" +
            "a.refund_amount,a.refund_account,a.refund_reason,a.refund_type,a.remark,a.currency_type AS currency,a.refund_id,a.actual_refund_amount AS approvalAmount\n" +
            "FROM t_series_order_tourist_refund_detail a\n" +
            "LEFT JOIN t_series_order_tourist_refund b ON a.refund_id = b.id\n" +
            "LEFT JOIN t_series_order_tourist_info c ON b.tourist_id = c.id " +
            "WHERE a.refund_id = #{refund_id} AND a.is_deleted = 0")
    List<OrderRefundDTO> queryListByRefund(@Param("refund_id")Long refundId);
}
